<?php
//微信-异步通知转发脚本
if ( !isset($GLOBALS['HTTP_RAW_POST_DATA']) ) {
	exit();
}

function getHost()
{
	if(isset($_SERVER['SERVER_PROTOCOL']))
	{
		$schemeArray = explode("/",$_SERVER['SERVER_PROTOCOL']);
		$scheme      = trim($schemeArray[0]);
	}
	$scheme  = $scheme ? $scheme : "http";
	$host	 = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '');
	$baseUrl = strtolower($scheme).'://'.$host;
	return $baseUrl;
}

ini_set('date.timezone','Asia/Shanghai');
error_reporting(E_ERROR);

require_once '../plugins/WxpayAPI_php_v3/example/log.php';
require_once '../classes/yun.php';

//初始化日志
$logHandler= new CLogFileHandler("../backup/logs/pay_wechat/".date('Y-m-d').'.log');
$log = Log::Init($logHandler, 15);

//获取通知的数据
$xml = $GLOBALS['HTTP_RAW_POST_DATA'];

Log::INFO("[接收数据开始]>>>\r\n".$xml);
$url = getHost().'/index.php';
$post_data = array(
	'controller' => 'yunblock',
	'action' => 'server_callback',
	'_id' => 13,
	'HTTP_RAW_POST_DATA' => $xml,
);
$opt = array(
	CURLOPT_POST => 1,
	CURLOPT_POSTFIELDS => $post_data,
);
$ret = Yun::curl_request($url,$opt);
Log::INFO('[接收数据结束反馈]'.$ret->response);
echo $ret->response;
